﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OCR
{
    public class Card
    {
        private CardType define = new CardType();

        /// <summary>
        /// 卡配置信息
        /// </summary>
        public CardType Define
        {
            get { return define; }
            set { define = value; }
        }

        private string imageName;
        /// <summary>
        /// 卡图片名称
        /// </summary>
        public string ImageName
        {
            get { return imageName; }
            set { imageName = value; }
        }


        /// <summary>
        /// 卡号图片名称 
        /// </summary>
        public string NoImageName
        {
            get
            {
                return this.imageName + "_NO.jpg";
            }
        }
        /// <summary>
        /// 密码图片名称 
        /// </summary>
        public string PwImageName
        {
            get
            {
                return this.imageName + "_PW.jpg";
            }
        }

        private string noValue;
        /// <summary>
        /// 卡号值
        /// </summary>
        public string NoValue
        {
            get
            {
                if (string.IsNullOrEmpty(this.noValue))
                {
                    if (this.define.NoRecognition.Type == 识别方法.混合)
                    {
                        //字符识别位数正确
                        if (this.noRecognitionValue.CharValue.Length == this.define.NoCount)
                        {
                            //条形码识别位数正确
                            if (this.noRecognitionValue.BarCodeValue.Length == this.define.NoCount)
                            {
                                //字符识别与条形码识别结果一致
                                if (this.noRecognitionValue.CharValue == this.noRecognitionValue.BarCodeValue)
                                {
                                    return this.noRecognitionValue.CharValue;
                                }
                                else
                                {
                                    //结果值=条形码值
                                    return this.noRecognitionValue.BarCodeValue;
                                }
                            }
                            else
                            {
                                return "";
                            }

                        }
                        else
                        {
                            return "";
                        }
                    }
                    else
                    {
                        if (this.define.NoRecognition.Type == 识别方法.字符)
                        {
                            //字符识别位数正确
                            if (this.noRecognitionValue.CharValue.Length == this.define.NoCount)
                            {
                                return this.noRecognitionValue.CharValue;

                            }
                            else
                            {

                                return "";
                            }
                        }
                        else//条形码识别
                        {
                            //条形码识别位数正确
                            if (this.noRecognitionValue.BarCodeValue.Length == this.define.NoCount)
                            {
                                return this.noRecognitionValue.BarCodeValue;

                            }
                            else
                            {
                                return "";
                            }

                        }
                    }
                }
                else
                {
                    return this.noValue;
                }
            }
            set { noValue = value; }
        }
        private string pwValue;
        /// <summary>
        /// 卡密码值
        /// </summary>
        public string PwValue
        {
            get
            {
                if (string.IsNullOrEmpty(this.pwValue))
                {
                    if (this.define.PwRecognition.Type == 识别方法.混合)
                    {
                        //字符识别位数正确
                        if (this.pwRecognitionValue.CharValue.Length == this.define.PwCount)
                        {
                            //条形码识别位数正确
                            if (this.pwRecognitionValue.BarCodeValue.Length == this.define.PwCount)
                            {
                                //字符识别与条形码识别结果一致
                                if (this.pwRecognitionValue.CharValue == this.pwRecognitionValue.BarCodeValue)
                                {
                                    return this.pwRecognitionValue.CharValue;
                                }
                                else
                                {
                                    return this.pwRecognitionValue.BarCodeValue;
                                }
                            }
                            else
                            {
                                return "";
                            }

                        }
                        else
                        {
                            return "";
                        }
                    }
                    else
                    {
                        if (this.define.PwRecognition.Type == 识别方法.字符)
                        {
                            //字符识别位数正确
                            if (this.pwRecognitionValue.CharValue.Length == this.define.PwCount)
                            {
                                return this.pwRecognitionValue.CharValue;

                            }
                            else
                            {
                                return "";
                            }
                        }
                        else//条形码识别
                        {
                            //条形码识别位数正确
                            if (this.pwRecognitionValue.BarCodeValue.Length == this.define.PwCount)
                            {
                                return this.pwRecognitionValue.BarCodeValue;

                            }
                            else
                            {
                                return "";
                            }

                        }
                    }
                }
                else
                {
                    return this.pwValue;
                }
            }
            set { pwValue = value; }
        }

        private RecognitionValue noRecognitionValue = new RecognitionValue();
        /// <summary>
        /// 卡号识别值
        /// </summary>
        public RecognitionValue NoRecognitionValue
        {
            get { return noRecognitionValue; }
            set
            {
                noRecognitionValue = value;

            }
        }
        private RecognitionValue pwRecognitionValue = new RecognitionValue();
        /// <summary>
        /// 密码识别值
        /// </summary>
        public RecognitionValue PwRecognitionValue
        {
            get { return pwRecognitionValue; }
            set
            {
                pwRecognitionValue = value;
            }
        }
        private bool isNoDoubt = false;
        /// <summary>
        /// 卡号是否可疑
        /// </summary>
        public bool IsNoDoubt
        {
            get
            {
                if (this.define.NoRecognition.Type == 识别方法.混合)
                {
                    //字符识别位数正确
                    if (this.noRecognitionValue.CharValue.Length == this.define.NoCount)
                    {
                        //条形码识别位数正确
                        if (this.noRecognitionValue.BarCodeValue.Length == this.define.NoCount)
                        {
                            //字符识别与条形码识别结果一致
                            if (this.noRecognitionValue.CharValue == this.noRecognitionValue.BarCodeValue)
                            {
                                return false;
                            }
                            else
                            {
                                //密码可疑
                                return true;
                            }
                        }
                        else
                        {
                            //密码可疑
                            return true;
                        }

                    }
                    else
                    {
                        //密码可疑
                        return true;
                    }
                }
                else
                {
                    if (this.define.NoRecognition.Type == 识别方法.字符)
                    {
                        //字符识别位数正确
                        if (this.noRecognitionValue.CharValue.Length == this.define.NoCount)
                        {
                            return false;

                        }
                        else
                        {
                            //密码可疑
                            return true;
                        }
                    }
                    else//条形码识别
                    {
                        //条形码识别位数正确
                        if (this.noRecognitionValue.BarCodeValue.Length == this.define.NoCount)
                        {
                            return false;

                        }
                        else
                        {
                            //密码可疑
                            return true;
                        }

                    }
                }
            }
        }
        private bool isPwDoubt = false;
        /// <summary>
        /// 密码是否可疑
        /// </summary>
        public bool IsPwDoubt
        {
            get
            {
                if (this.define.PwRecognition.Type == 识别方法.混合)
                {
                    //字符识别位数正确
                    if (this.pwRecognitionValue.CharValue.Length == this.define.PwCount)
                    {
                        //条形码识别位数正确
                        if (this.pwRecognitionValue.BarCodeValue.Length == this.define.PwCount)
                        {
                            //字符识别与条形码识别结果一致
                            if (this.pwRecognitionValue.CharValue == this.pwRecognitionValue.BarCodeValue)
                            {
                                return false;
                            }
                            else
                            {
                                //密码可疑
                                return true;
                            }
                        }
                        else
                        {
                            //密码可疑
                            return true;
                        }

                    }
                    else
                    {
                        //密码可疑
                        return true;
                    }
                }
                else
                {
                    if (this.define.PwRecognition.Type == 识别方法.字符)
                    {
                        //字符识别位数正确
                        if (this.pwRecognitionValue.CharValue.Length == this.define.PwCount)
                        {
                            return false;

                        }
                        else
                        {
                            //密码可疑
                            return true;
                        }
                    }
                    else//条形码识别
                    {
                        //条形码识别位数正确
                        if (this.pwRecognitionValue.BarCodeValue.Length == this.define.PwCount)
                        {
                            return false;

                        }
                        else
                        {
                            //密码可疑
                            return true;
                        }

                    }
                }
            }
        }
    }
    public class RecognitionValue
    {
        private string charValue;
        /// <summary>
        /// 字符识别值
        /// </summary>
        public string CharValue
        {
            get { return this.charValue; }
            set { this.charValue = value; }
        }

        private string barCodeValue = "";
        /// <summary>
        /// 条形码识别值
        /// </summary>
        public string BarCodeValue
        {
            get { return this.barCodeValue; }
            set { this.barCodeValue = value; }
        }
    }
}
